<?php

namespace app\controller\v1;

use app\model\CompanyModel;
use app\validate\CompanyValidate;
use think\response\Json;

class Company extends System
{

    /**
     * Notes: 企业列表
     * User: chenLei
     * Date: 9/25/25
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     */
    public function list()
    {
        $companyModel = new CompanyModel();
        $res = $companyModel->list($this->params);

        return $this->successJson($res);
    }


    /**
     * Notes: 添加企业
     * User: chenLei
     * Date: 9/25/25
     * @return \think\response\Json
     */
    public function add()
    {
        $validate = new CompanyValidate();
        if (!$validate->scene('add')->check($this->params)) {
            return $this->errorJson($validate->getError());
        }

        $companyModel = new CompanyModel();
        $res = $companyModel->add($this->params);
        if ($res === false) {
            return $this->errorJson($companyModel->getError());
        }
        return $this->successJson();
    }


    /**
     * Notes: 企业编辑
     * User: chenLei
     * Date: 9/25/25
     * @return \think\response\Json
     */
    public function edit()
    {
        $validate = new CompanyValidate();
        if (!$validate->scene('edit')->check($this->params)) {
            return $this->errorJson($validate->getError());
        }

        $companyModel = new CompanyModel();
        $res = $companyModel->edit($this->params);
        if ($res === false) {
            return $this->errorJson($companyModel->getError());
        }
        return $this->successJson();
    }


    /**
     * Notes: 删除企业
     * User: chenLei
     * Date: 9/25/25
     * @return \think\response\Json
     */
    public function del()
    {
        $validate = new CompanyValidate();
        if (!$validate->scene('del')->check($this->params)) {
            return $this->errorJson($validate->getError());
        }

        $companyModel = new CompanyModel();
        $res = $companyModel->del($this->params);
        if ($res === false) {
            return $this->errorJson($companyModel->getError());
        }
        return $this->successJson();
    }


    /**
     * Notes: 获取所有企业列表
     * User: chenLei
     * Date: 9/26/25
     * @return \think\response\Json
     */
    public function listAll()
    {

        $companyModel = new CompanyModel();
        $res = $companyModel->listAll($this->params);
        return $this->successJson($res);

    }
}